package com.sc.nft.dao;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.BoxTakePool;
import com.sc.nft.entity.vo.BoxPoolVO;
import com.sc.nft.enums.BoxTakePoolConvertScenarioEnum;
import com.sc.nft.mapper.BoxTakePoolMapper;
import com.sc.nft.sup.SuperEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

/**
 * 盲盒抽奖池(sc_box_take_pool)数据DAO
 *
 * @author 张翔宇
 * @description 盲盒抽奖池
 * @since 2023-04-03 18:03:44
 */
@Slf4j
@Repository
public class BoxTakePoolDao extends ServiceImpl<BoxTakePoolMapper, BoxTakePool> {

    public Page<BoxPoolVO> boxPoolPage(Boolean status, String name, BoxTakePoolConvertScenarioEnum convertScenario, Long daoId, int pageNo, int pageSize) {
        Page<BoxPoolVO> page = new Page<>(pageNo, pageSize);
        return this.baseMapper.boxPoolPage(page, status, name, Objects.nonNull(convertScenario) ? convertScenario.getCode() : null, daoId);
    }

    public Page<BoxPoolVO> boxPoolWebPage(Boolean status, String name, BoxTakePoolConvertScenarioEnum convertScenario, Long daoId, int pageNo, int pageSize) {
        Page<BoxPoolVO> page = new Page<>(pageNo, pageSize);
        return this.baseMapper.boxPoolWebPage(page, status, name, Objects.nonNull(convertScenario) ? convertScenario.getCode() : null, daoId);
    }

    public Page<BoxPoolVO> voucherConversion(Boolean status, String name, BoxTakePoolConvertScenarioEnum convertScenario, Long daoId, int pageNo, int pageSize) {
        Page<BoxPoolVO> page = new Page<>(pageNo, pageSize);
        return this.baseMapper.voucherConversion(page, status, name, Objects.nonNull(convertScenario) ? convertScenario.getCode() : null, daoId);
    }

    public Page<BoxPoolVO> voucherWebConversion(Boolean status, String name, BoxTakePoolConvertScenarioEnum convertScenario, Long daoId, int pageNo, int pageSize) {
        Page<BoxPoolVO> page = new Page<>(pageNo, pageSize);
        return this.baseMapper.voucherWebConversion(page, status, name, Objects.nonNull(convertScenario) ? convertScenario.getCode() : null, daoId);
    }

    public BoxTakePool getIdAndStatus(Long boxId, boolean b) {
        return lambdaQuery().eq(BoxTakePool::getId, boxId).eq(BoxTakePool::getStatus, b).one();
    }

    public BoxTakePool getProductBoxIdAndStatus(Long boxId, boolean b) {
        return lambdaQuery().eq(BoxTakePool::getProductBoxId, boxId).eq(BoxTakePool::getStatus, b).one();
    }

    public void sortModification(Long id, Integer ranking) {
        lambdaUpdate().eq(BoxTakePool::getId, id).set(BoxTakePool::getRanking, ranking).update();
    }


    /**
     * 获取上架中的活动
     *
     * @return
     */
    public List<BoxTakePool> getUpperActivity(Integer type) {
        return lambdaQuery().eq(SuperEntity::getIsDelete, Boolean.FALSE).eq(BoxTakePool::getStatus, 1).
                eq(SuperEntity::getIsDelete, Boolean.FALSE).eq(BoxTakePool::getType, type).list();
    }
}